import {useEffect, useState} from 'react';
// 只执行一次的函数
export const useMount = (callback: () => void) => {
    useEffect(
        () => {
            callback();
        }, 
        [callback]
    );
};

// 防抖函数
let timer: NodeJS.Timeout;

// 防抖函数
export const useDebounce = <T>(value: T, delay?: number): T => {
    const [debounceValue, setDebounceValue] = useState(value);

    useEffect(() => {
        timer = setTimeout(() => setDebounceValue(value), delay);
        return () => clearTimeout(timer);
    }, [value, delay]);

    return debounceValue;
};

export {default as useMenuList} from './useMenuList';